# 登录接口调用
import requests

from common.DBUtil import DBUtil

url_login= "http://ihrm-test.itheima.net/api/sys/login"
headers = {"Content-Type": "application/json"}
body={"mobile": "13800000002", "password": "123456"}
resp=requests.post(url_login,headers=headers,json=body)
print(resp.json())

# 员工管理-新增员工（令牌）employee
token="Bearer "+resp.json().get("data")
sql="delete from bs_user where mobile='18210222282';"
DBUtil.uid_db(sql)
url_add_emp="http://ihrm-test.itheima.net/api/sys/user"
headers={"Content-Type": "application/json",
         "Authorization":token}
body_add=({"username": "YG001","mobile": "18210222282","workNumber": "123"})
resp_add=requests.post(url_add_emp,headers=headers,json=body_add)
print(resp_add.json())

# 员工管理-查询员工
id=resp_add.json().get("data").get("id")   #固定传参
url_query=f"http://ihrm-test.itheima.net/api/sys/user/{id}"
resp_query=requests.get(url_query,headers=headers)
print("查询员工:", resp_query.json())

# 员工管理-修改员工
url_modify=f"http://ihrm-test.itheima.net/api/sys/user/{id}"
body_modify=({"username": "YG002","password": "123456","departmentId": "10066"})
resp_modify=requests.put(url_modify,headers=headers,json=body_modify)
print("修改员工:",resp_modify.json())

#员工管理-删除员工
url_delete=f"http://ihrm-test.itheima.net/api/sys/user/{id}"
resp_delete=requests.delete(url_delete,headers=headers)
print("删除员工:",resp_delete.json())